package icu.qx.gbs.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.R;
import icu.qx.gbs.domain.GbsGoodUnit;
import icu.qx.gbs.service.IGbsGoodUnitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 物品单位Controller
 *
 * @author ruoyi
 * @date 2024-06-06
 */
@RestController
@RequestMapping("/gbs/unit")
public class GbsGoodUnitController extends BaseController {
    @Autowired
    private IGbsGoodUnitService gbsGoodUnitService;

    /**
     * 查询物品单位列表 分页
     */
    @RequiresPermissions("gbs:unit:list")
    @GetMapping("/list")
    public TableDataInfo list(GbsGoodUnit gbsGoodUnit) {
        startPage();
        List<GbsGoodUnit> list = gbsGoodUnitService.selectGbsGoodUnitList(gbsGoodUnit);
        return getDataTable(list);
    }

    /**
     * 查询物品单位列表 所有
     */
    @GetMapping("/all")
    public R<List<GbsGoodUnit>> all(GbsGoodUnit gbsGoodUnit) {
        List<GbsGoodUnit> list = gbsGoodUnitService.selectGbsGoodUnitList(gbsGoodUnit);
        return R.ok(list);
    }

    /**
     * 导出物品单位列表
     */
    @RequiresPermissions("gbs:unit:export")
    @Log(title = "物品单位", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GbsGoodUnit gbsGoodUnit) {
        List<GbsGoodUnit> list = gbsGoodUnitService.selectGbsGoodUnitList(gbsGoodUnit);
        ExcelUtil<GbsGoodUnit> util = new ExcelUtil<GbsGoodUnit>(GbsGoodUnit.class);
        util.exportExcel(response, list, "物品单位数据");
    }

    /**
     * 获取物品单位详细信息
     */
    @RequiresPermissions("gbs:unit:query")
    @GetMapping(value = "/{guId}")
    public AjaxResult getInfo(@PathVariable("guId") Long guId) {
        return success(gbsGoodUnitService.selectGbsGoodUnitByGuId(guId));
    }

    /**
     * 新增物品单位
     */
    @RequiresPermissions("gbs:unit:add")
    @Log(title = "物品单位", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GbsGoodUnit gbsGoodUnit) {
        return toAjax(gbsGoodUnitService.insertGbsGoodUnit(gbsGoodUnit));
    }

    /**
     * 修改物品单位
     */
    @RequiresPermissions("gbs:unit:edit")
    @Log(title = "物品单位", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GbsGoodUnit gbsGoodUnit) {
        return toAjax(gbsGoodUnitService.updateGbsGoodUnit(gbsGoodUnit));
    }

    /**
     * 删除物品单位
     */
    @RequiresPermissions("gbs:unit:remove")
    @Log(title = "物品单位", businessType = BusinessType.DELETE)
    @DeleteMapping("/{guIds}")
    public AjaxResult remove(@PathVariable Long[] guIds) {
        return toAjax(gbsGoodUnitService.deleteGbsGoodUnitByGuIds(guIds));
    }
}
